package kr.hkit.powerjava.chapter26.common;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DbUtil {

	public static void close(Connection connection) {
		if(connection != null) {
			try {
				connection.close();
			} catch (SQLException e) {
				System.err.println(e);
			} finally {
				connection = null;
				System.out.println("MySQL Connection Close!!");
			}
		}
	}
	
	public static void close(PreparedStatement pstmt) {
		if(pstmt != null) {
			try {
				pstmt.close();
				} catch (SQLException e) {
				System.err.println(e);
			} finally {
				pstmt = null;
			}
		}
	}
	
	public static void close(ResultSet rs) {
		if(rs != null) {
			try {
				rs.close();
				} catch (SQLException e) {
				System.err.println(e);
			} finally {
				rs = null;
			}
		}
	}
	public static void close(PreparedStatement pstmt, Connection connection) {
		close(pstmt);
		close(connection);
	}
	
	public static void close(ResultSet rs, PreparedStatement pstmt, Connection connection) {
		close(rs);
		close(pstmt, connection);
	}
}